/*
 * ScriptElement.cpp
 *
 *  Created on: 2010-6-7
 *      Author: Guobc
 */

#include "ScriptElement.h"
#include "TextNode.h"
using namespace HA;
using namespace std;

string ScriptElement::mIds[] = { "SCRIPT" , ""};
string ScriptElement::mEnds[] = { "SCRIPT", "BODY", "HTML" , ""};

ScriptElement::ScriptElement() :
	HA::CommonElement(), mCode("") {

}

string ScriptElement::getScriptCode(){
	if(mCode.empty()){
		ASTNodeList children = getChildren();
		ASTNode* node;
		TextNode* textNode;
		int size = children.size();
		for(int i = 0; i < size; i++){
			node = children.item(i);
			textNode = dynamic_cast<TextNode*> (node);
			if(textNode != NULL){
				return textNode->getText();
			}
		}
	}else{
		return mCode;
	}
	return "";
}
